#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;
LL f[N];
int main()
{
	int n, m; cin >> n >> m;
	int x, b;
	for(int i = 1; i <= n; i++)
	{
		cin >> x >> b;
		f[x] += b; 
	}
	for(int i = 1; i <= N; i++)
		f[i] += f[i-1]; 
	LL res = 0;
	for(int i = m; i <= N; i++)
		res = max(res, f[i] - f[i-m]);
	cout << res << endl;
	return 0;
 } 